﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width:700px; margin-top: 50px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire" title="创建订单"></i>&nbsp;&nbsp;新增访问记录</h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/user-source/create-record" data-validate="true">
    
      <div class="modal-body">
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">访客</label>
          <div class="pull-left col-xs-7">
            <input name="mobile" type="text" class="form-control" value="${userSource.mobile}" readonly="readonly">
          </div>
        </div>
        
        <c:if test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
          <input type="hidden" name="siteId" value="${currentPrincipal.site.id}">
        </c:if>
        
       <c:if test="${currentPrincipal.root or currentPrincipal.admin or currentPrincipal.areaServer or currentPrincipal.areaManager}">
          <div class="form-group x-form-group">
            <label class="col-xs-3 control-label">门店</label>
            <div class="col-xs-3">
              <select name="siteId" class="form-control" data-validate="required">
                <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                  <option value="${site.id}">${site.name}</option>
                </c:forEach>
              </select>
            </div>
          </div>
        </c:if>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">回访渠道</label>
          <div class="pull-left col-xs-3">
            <select name="type" class="form-control" data-validate="required">
              <option value=""></option>
              <option value="电话访问">电话访问</option>
              <option value="门店回访">门店回访</option>
              <option value="微信回访">微信回访</option>
            </select>
          </div>
          <label class="col-xs-3 control-label">接待人</label>
          <div class="pull-left col-xs-3">
            <select name="receiver" class="form-control">
              <option value=""></option>
              <c:forEach var="principal" items="${persist.principals}">
                <c:if test="${!principal.disabled}">
                  <option value="${principal.id}" ${param.reciver eq principal.id ? 'selected' : ''}>${principal.profile.realname}</option>
                </c:if>
              </c:forEach>
            </select>
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">学员需求</label>
          <div class="pull-left col-xs-8">
            <input name="description" type="text" class="form-control" value="${param.reason}">
          </div>
        </div>
        
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label">访问信息备注</label>
          <div class="pull-left col-xs-8">
            <input name="remark" type="text" class="form-control">
          </div>
        </div>
        
      </div>

      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div> 
    </form>

  </div>

</div>

<script src="${ctx.resource}/js/component/bootstrap.validate.js"></script>
<script src="${ctx.resource}/js/component/bootstrap.validate.en.js"></script>
<script src="${ctx.resource}/js/bootstrap.validate.trigger.js"></script>
<script>
$(document).ready(function(){
  
  $('select[name="gender"]').select2({
        placeholder : '请选择',
        minimumResultsForSearch : 5,
        allowClear : true,
      });
    
  
  var sourceType = $('select[name="userSourceType"]').select2({
      placeholder : '请选择渠道',
      minimumResultsForSearch : 5,
      allowClear : true,
    });
  
  $('select[name="userSourceType"]').on("change", function(e) { 
    console.log("change "+JSON.stringify({val:e.val, added:e.added, removed:e.removed}));
    if(e.val == '0') {
      $("#addNew").hasClass("hide") ? $("#addNew").removeClass("hide") : null;
    } else {
      $("#addNew").hasClass("hide") ? null : $("#addNew").addClass("hide");
    }
    })
  
  $('select[name="siteId"]').select2({
      placeholder : '请选择门店',
      minimumResultsForSearch : 5,
      allowClear : true,
    });
  
  $('select[name="receiver"]').select2({
      placeholder : '请选择接待人',
      minimumResultsForSearch : 5,
      allowClear : true,
    });
  
  $('select[name="phoneReciver"]').select2({
      placeholder : '请选择前台电话接待人',
      minimumResultsForSearch : 5,
      allowClear : true,
    });
  
  $('form').shiftform({
    beforeSubmit : function(el) {
      $('form').trigger("validate.ajax.submit");
      return $.bt_validate.result[$.bt_validate.form_id]
    }
  });
});
</script>